package com.springmvc.netty.action;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.springmvc.netty.core.ActionMap;
import com.springmvc.netty.core.NettyController;
import com.springmvc.utils.majiang.Param;
import com.springmvc.utils.result.ResultMsg;
import com.springmvc.web.majiang.entity.User;
import com.springmvc.web.majiang.service.IUserService;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

@NettyController()
public class UserAction extends BaseAction {

	@Autowired
	private IUserService userService;

	@ActionMap(key = 1)
	public void login(ChannelHandlerContext ctx, Param param) {
		User user = this.userService.selectById(param.getUserid());
		System.out.println(String.format("用户昵称:%s;密码%d;传人内容%s", user.getUsername(), user.getId(), param.getMj()));
		//		ctx.channel().writeAndFlush(new TextWebSocketFrame(user.getUsername()));
		Map<String, String> data = new HashMap<String, String>();
		data.put("username", user.getUsername());
		writeAndFlush(ctx, ResultMsg.SUCCESS(param.getCammand(), data));
	}
}